<?php

class Contact extends AppModel {
  public $useTable = false;
  public $name = 'contact';
  public $validate = array(
      'introduce' => array(
                'rule' => 'notEmpty',
                'message'=>'Introduce yourself is required'
            ),
      'name' => array(
          'rule' => 'notEmpty',
          'message'=>'Name is required'
      ),
      'email_address' => array(
          'contactMethodRule'=>array(
            'rule'=>array('validateContactMethod','phone'),
            'message'=>'Please specify an email address or phone number'
          ),
          'emailRule'=>array(
            'rule' => array('email',true),
            'allowEmpty'=> true,
            'required'=>false,
            'message'=>'Specify a valid email address'
          )
      ),
      'phone' => array(
          'rule' => array('phone',null,'us'),
          'allowEmpty'=> true,
          'required'=>false,
          'message'=>'Specify a valid email phone number'
      ),
      'message' => array(
          'rule' => 'notEmpty',
          'message'=>'Message is required'
      ),
      'captcha_text' => array(
          'rule' => 'notEmpty',
          'message'=>'Image characters is required'
      )
  );

  function validateContactMethod($field, $otherContactField){
    $retVal = false;
    $fieldValue = array_values($field);
    if(!empty($fieldValue[0]) || !empty($this->data[ucfirst($this->name)][$otherContactField])) {$retVal=true;}
    return $retVal;
  }
  
}

?>
